package com.meisupic.copyright.util;

import com.meisupic.copyright.domain.vo.CategroyVo;
import com.meisupic.copyright.service.ICopyRightWorksService;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author lanjian
 * @Date 2018/2/9 上午10:19
 */
@Component
public class CategoryUtil {

  private static ICopyRightWorksService staticCopyRightWorksService;

  @Autowired
  private ICopyRightWorksService copyRightWorksService;

  private static Map<Integer, String> categoryMap = new HashedMap();

  @PostConstruct
  public void init() {
    CategoryUtil.staticCopyRightWorksService = copyRightWorksService;
  }


  public static Map<Integer, String> getCategoryMap() {
    if (categoryMap.isEmpty()) {
      List<CategroyVo> categroyVoList = staticCopyRightWorksService.findCategoryVoList();
      for (CategroyVo categroyVo : categroyVoList) {
        categoryMap.put(categroyVo.getCatId(), categroyVo.getCatName());
      }
    }
    return categoryMap;
  }

  public static String getCategoryName(int id) {
    if (categoryMap.isEmpty()) {
      getCategoryMap();
    }
    return categoryMap.get(id);
  }
}
